Learning Objectives

After completing this lesson, you'll be able to:

Overview

The Generic Reader and Generic Writer allow you to free FME workspaces from format restrictions.

Where all other readers and writers correspond to a specific data format, the Generic Reader and Generic Writer are not. The Generic Reader can read almost any data format, and the Generic Writer can write almost any data format.

In that way, a single workspace can process different data formats without being expressly set up for that format.

The Generic Reader

The Generic reader acts as a wrapper for the true reader, which FME uses during the translation. At runtime, once the actual reader is known, the Generic reader will do its best to represent the intention of the translation in the chosen input format.

The Generic reader takes a file or multiple files, folders, URLs, or database names as the input dataset. If the format requires an input folder, the Generic reader will turn the input filename into a folder by removing the file name part of the path.

Note

The format the Generic reader will read from is (by default) a Published Parameter. To set up specific data flows for a particular format, workspace authors can use the ParameterFetcher transformer to retrieve the read data's format name and potentially route features to other transformers using this value. The Generic reader reads the features using the underlying reader. See the ParameterFetcher help for more information.

Adding an Additional Reader or a Schema Reader to a Workspace

It is sometimes helpful to pre-configure parameters specific to individual input formats. For example, you must specify a collection of connection parameters to read from a database.

You can add a reader or a schema reader to the workspace. The first reader in the workspace will be Generic, containing all the input feature types. The second reader may or may not have feature types but will be used to communicate any format-specific reader settings to the Generic reader when the Generic reader uses that format.

For example, if you set the Input Format to Microsoft SQL Server Spatial, the Microsoft SQL Server Spatial reader that the Generic reader uses will adopt the format settings specified for the Microsoft SQL Server Spatial reader. Think of it this way: the Generic reader will look for readers matching the input data it receives; if it finds any, it will use their parameters. If it doesn't find any, it will use the defaults.

You use a Generic Reader the same as any other reader: by specifying the format in the Add Reader or Generate Workspace dialogs or in Quick Add:

Add Reader dialog showing Generic as selected

This source dataset is an AutoCAD DWG dataset, but FME does not know that yet. FME examines the file's extension when you run the workspace to determine the format.

At a later time, the end-user might then choose a different file - in a completely different format - to be read, like so:

Changing the Source Dataset

Again, at runtime, FME examines the file extension to identify the data format and then - having discovered it is MicroStation DGN - reads it just as if it were a regular DGN reader.

That way, a single reader can read any data format.

Note

You think there must be a catch, right? Well, it's true. Firstly this technique only works with file-based formats (it won't work on a database or web format). Secondly, the Generic Reader is not immune from the Unexpected Input Remover, so switching datasets - regardless of format - only works with a compatible schema (see below).

Generic Reader Feature Types

The Unexpected Input Remover is the function in FME that filters incoming data against the list of permitted feature types. If you don't define the incoming data in the workspace, FME will drop it from the translation.

In the previous example, a layer called "TrafficSignals" stored the traffic signals data in AutoCAD format, and the workspace names the reader feature type to correspond. But, if the MicroStation file stored data on a different layer, then this would be the result:

Dropped features because layers were not defined as feature types

FME dropped all 778 records from the translation. So, although the Generic Reader allows you to read datasets of different formats, the limitation is that each dataset must have its layers defined as feature types in the workspace.

Of course, an easy way to allow all layers to pass is to set a Merge Feature Type in the Feature Type Properties:

Addressing the dropped features issue by using Merge Feature Type

With that setup, any data layer can be passed into the workspace, regardless of format. Of course, even then, you must be careful about assuming what attributes will be available!

Tips for Using the Generic Reader

The Generic reader does not allow you to specify parameters that define the reader's behavior for any specific format. However, you can bypass this limitation by using the Generic reader and adding a reader as a resource.

For example, when a Generic reader reads GML data, you may want to specify a particular SRS axis order. To accomplish this task, select Readers > Add Reader as Resource from the Workbench menu bar, and specify the GML format and any GML dataset (which dataset does not matter). In the parameters dialog, specify the value you want for GML SRS Axis Order.

Adding a Reader as a Resource and setting a parameter

When you finish creating the resource reader, it appears in the Navigator, under Workspace Resources, along with all of its parameters:

Workspace Resources in the Navigator showing the resource reader

When the workspace runs, the Generic reader uses this resource to read GML data with the desired SRS axis order.

For more information about resource readers, see Adding a Reader as a Resource in the FME Workbench help.

Note

Generic Readers only deal with a flexible format but can also be set up to be flexible with layers using a Merge Filter. However, each dataset the workspace reads must have the same attribute schema. This part is not flexible. Flexible attribute schemas require the use of a Dynamic Translation.